package internal

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"

	"gitee.com/lzppppp/zabbix-api/cfg"
)

func Post(data cfg.PostDataJson) []byte {

	// json格式化
	bytes, _ := json.Marshal(data)
	fmt.Println(string(bytes))

	// 带header的post方法
	r, err := http.Post(
		"http://192.168.100.192/zabbix/api_jsonrpc.php",
		"application/json-rpc",
		strings.NewReader(string(bytes)),
	)

	if err != nil {
		fmt.Println("Read body failed:", err)
	}

	// 读取post返回的数据
	body, _ := ioutil.ReadAll(r.Body)

	return body

}
